package org.builder.service;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.builder.xml.Menu;
import org.builder.xml.MenuItem;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

import junit.framework.TestCase;

public class MenuServiceImplTest extends TestCase {

	protected MenuServiceImpl menuService=new MenuServiceImpl();
	


	public void testInitMenu() {
		menuService.setXmlConfig("classpath:menu.xml");
		UnmarshallServiceImpl u =new UnmarshallServiceImpl();
		u.setMappingLocation("classpath:/menu.cm.xml");
		menuService.setMenuUnmarshallService(u);
		try {
			menuService.initMenu();
			Map map = menuService.getMenuMap();
			Collection<Menu> menus = map.values();
			System.err.println(map);
			System.out.println(menus);
			for (Iterator iter = menus.iterator(); iter.hasNext();) {
				Menu m = (Menu) iter.next();
				Set<MenuItem> items = m.getItems();
				for (Iterator iterator = items.iterator(); iterator.hasNext();) {
					MenuItem element = (MenuItem) iterator.next();
					System.out.println(element.getName()+", "+element.isHeader());
					
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
